# encoding=utf8

from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_moment import Moment
from flask_migrate import Migrate
from flask_uploads import UploadSet, IMAGES, configure_uploads, patch_request_class
from flask_mail import Mail
from flask_socketio import SocketIO

bootstrap = Bootstrap()
db = SQLAlchemy()
migrate = Migrate(db=db)
login_manager = LoginManager()
moment = Moment()
mail = Mail()
photos = UploadSet('photos', IMAGES)
socket_io = SocketIO()
async_mode = None


def init_extensions(app):
    bootstrap.init_app(app)
    db.init_app(app)
    migrate.init_app(app)
    login_manager.init_app(app)
    moment.init_app(app)
    mail.init_app(app)
    socket_io.init_app(app)

    configure_uploads(app, photos)
    patch_request_class(app, None)

    login_manager.login_view = 'users.login'
    login_manager.login_message = '需要先登录'
    login_manager.session_protection = 'strong'
